package com.cq.oa.service.sm.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import oa.base.service.impl.BaseServiceImpl;
import oa.base.session.SessionManger;

import com.cq.oa.dao.sm.UserOrgDao;
import com.cq.oa.domain.sm.Org;
import com.cq.oa.domain.sm.UserOrg;
import com.cq.oa.service.sm.OrgService;
import com.cq.oa.utils.StringliptUtil;

public class OrgServiceImpl extends BaseServiceImpl<Org> implements OrgService{

	
	private UserOrgDao userOrgDao;
	
	
	
	public void setUserOrgDao(UserOrgDao userOrgDao) {
		this.userOrgDao = userOrgDao;
	}



	/* (non-Javadoc)
	 * @see com.cq.oa.service.sm.OrgService#saveUserOrg(java.lang.String, java.lang.Long)
	 */
	public void saveUserOrg(String userIds,String userNames,Long deptId,String deptName){
		List<Long> user = StringliptUtil.string2Long(StringliptUtil.split(userIds));
		String[] name = StringliptUtil.split(userNames);
		List<UserOrg> userOrgs = new ArrayList<UserOrg>();
		for(int i=0;i<user.size();i++){
			UserOrg org = new UserOrg();
			org.setUserSid(user.get(i));
			org.setUserCname(name[i]);
			org.setDeptSid(deptId);
			org.setDeptCname(deptName);
			org.setOrgSid(SessionManger.getOrgId());
			userOrgs.add(org);
		}
		this.userOrgDao.saveAll(userOrgs);
		
	}



	@Override
	public void delete(Long sid) {
		super.delete(sid);
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("orgSid", SessionManger.getOrgId());
		params.put("deptSid", sid);
		this.userOrgDao.remove(params);
	}

	
	
	
	

}
